<template>
  <div class="data-statistic">
    <data-row :col="4">
      <template #default="{ span }">
        <el-col v-for="(item,index) in data" :key="index" v-bind="span">
          <el-card class="panel-row app-tap" shadow="house" @click="tapPanel(item,index)">
            <el-statistic v-bind="item"/>
          </el-card>
        </el-col>
      </template>
    </data-row>
  </div>
</template>

<script lang="ts">
import {defineComponent, PropType} from 'vue'

export type DataStatisticItem = {
  title: string, value?: number, suffix?: string, precision?: number, prefix?: string
}

export default defineComponent({
  name: 'DataStatistic',
  emits: {
    tap: (item: DataStatisticItem, index: number) => true
  },
  props: {
    data: {
      type: Array as PropType<Array<DataStatisticItem>>,
      required: true
    }
  },
  setup(props, {emit}) {
    return {
      tapPanel(item: DataStatisticItem, index: number) {
        emit('tap', item, index)
      }
    }
  }
})
</script>

<style lang="scss" scoped>
.data-statistic {

  .panel-row {
    margin-bottom: var(--app-interval);
    padding: 5px;

    .el-statistic {
      :deep(.el-statistic__head) {
        font-size: 16px;
        margin-bottom: var(--app-interval);
      }
    }
  }
}
</style>